#define _GNU_SOURCE
#include "unistd.h"
#include  <pthread.h>
#include "log.h"

static void *thread_func1(void *arg)
{   int count=100;
    for (size_t i = 0; i < count; i++)
    {
        sleep(1);
        log_info("thread1 %ld is running : %d" ,gettid(),  i);    
    }
    return NULL;
}

static void *thread_func2(void *arg)
{   int count=15;
    for (size_t i = 0; i < count; i++)
    {
        sleep(1);
        log_info("thread2 %ld is running : %d" ,gettid(),  i);    
    }
    return NULL;
}

int main(int argc, char const *argv[])
{
    
    //1 声明两个线程的标识符
    pthread_t thread1, thread2;
    //2 开辟两个线程
    pthread_create(&thread1, NULL, thread_func1, NULL);
    pthread_create(&thread2, NULL, thread_func2, NULL);
    sleep(5);
    pthread_cancel(thread1);
    log_info( "main thread  is waiting");
    pthread_join(thread2, NULL); //1 等待线程结束 2 获得线程的结果
    log_info( "all threads  are over . ");
    return 0;
}
